from django_redis import get_redis_connection

class MyReids:
  def __init__(self):
    self.redis = get_redis_connection(alias="code")
  def set_code(self,phone,code):
    self.redis.set(phone,code,60*2)
  def get_code(self,phone):
    code=self.redis.get(phone)
    if code:
        return code.decode("utf-8")
    else:
        return None

myredis=MyReids()